package com.delta.rafg.core.database.impl;

import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import com.delta.rafg.core.config.ConfigSettings;
import com.delta.rafg.core.database.DataHandlerOptions;
import com.delta.rafg.core.exception.RAFGException;

public abstract class ACacheDataHandler extends ADataHandler {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3052362430817583329L;
	/**
	 * Holds the cacheSchemaSuffix property.
	 */
	private String cacheSchemaSuffix = "_CACHE";

    public void initialize(DataHandlerOptions options) throws RAFGException {
        super.initialize(options);
        ConfigSettings configSettings = options.getConfigSettings();
        String schemaSuffix = configSettings.getProperty(getDataHandlerPropertyPrefix() + ".schemasuffix");
        if (schemaSuffix != null) {
            this.cacheSchemaSuffix = schemaSuffix;
        }
    }

    public String getCacheSchemaSuffix() {
        return cacheSchemaSuffix;
    }

    public abstract boolean isSchemaExistsException(SQLException e);

	public abstract boolean checkTableExists(Statement stmt, String cacheTable) throws RAFGException;

	public static class CacheTableColumnInfo {
		private String columnName;
		private int columnType = java.sql.Types.VARCHAR;
		private int columnLen = 50;
		private int columnScale = 0;
		private boolean isNullable = true;
		private boolean isPrimaryKey = false;
		
		@SuppressWarnings("unused")
		private CacheTableColumnInfo() {
		}
		
		/**
		 * @param columnName
		 * @param columnType
		 * @param columnLen
		 * @param isPrimaryKey
		 */
		public CacheTableColumnInfo(String columnName, int columnType, int columnLen, boolean isPrimaryKey) {
			this.columnName = columnName;
			this.columnType = columnType;
			this.columnLen = columnLen;
			this.isPrimaryKey = isPrimaryKey;
		}

		/**
		 * @param columnName
		 * @param columnType
		 * @param columnLen
		 * @param columnScale
		 * @param isPrimaryKey
		 * @param isNullable
		 */
		public CacheTableColumnInfo(String columnName, int columnType, int columnLen, int columnScale, boolean isPrimaryKey, boolean isNullable) {
			this.columnName = columnName;
			this.columnType = columnType;
			this.columnLen = columnLen;
			this.columnScale = columnScale;
			this.isNullable = isNullable;
			this.isPrimaryKey = isPrimaryKey;
		}

		public String getColumnName() {
			return columnName;
		}

		public int getColumnType() {
			return columnType;
		}

		public int getColumnLen() {
			return columnLen;
		}
		
		public boolean isPrimaryKey() {
			return isPrimaryKey;
		}

		public int getColumnScale() {
			return columnScale;
		}

		public boolean isNullable() {
			return isNullable;
		}
		
	}
	
    //These don't apply to a cache datasource
	@Override
	public POLL_STYLE getPollStyle() {
		return null;
	}

	@Override
	public String getPollFrequency() {
		return null;
	}

	public void createCacheTable(String cacheTable, List<CacheTableColumnInfo> columns) throws RAFGException {

	}
}
